package org.rui;


import lombok.extern.slf4j.Slf4j;
import org.rui.example.common.model.User;
import org.rui.example.common.service.UserService;
import org.rui.rpc.config.RpcConfig;
import org.rui.rpc.proxy.ServiceProxyFactory;
import org.rui.rpc.util.ConfigUtils;

/**
 * @author: linweirui
 * @date: 2024/12/02 10:52
 */
@Slf4j
public class EasyConsumerApplication {
    public static void main(String[] args) {
        //根据resource目录下的配置文件加载配置 如果没有则加载默认配置
        RpcConfig rpc = ConfigUtils.loadConfig(RpcConfig.class, "rpc");
        System.out.println(rpc);
        //静态代理
        //UserService userService = new UserServiceProxy();
        // 动态代理,获得对应实现类服务代理-》序列化获得注册节点信息封装去etcd寻找对应地址-》发送请求
        // ->rpc的httphandle拦截处理请求-》
        UserService userService = ServiceProxyFactory.getProxy(UserService.class);
        User user = new User();
        user.setName("rui");
        // 调用
        User newUser = userService.getUser(user);
        if (newUser != null) {
            log.info("输出的名字是============================{}",newUser.getName());
        } else {
            System.out.println("user == null");
        }
//        short number = userService.getNumber();
//        System.out.println("========number is "+number);
    }

}